package com.istock.state.demo.service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.istock.state.demo.constants.ChildOrderStatusEnum;
import com.istock.state.demo.dao.OrderGoodsMapper;
import com.istock.state.demo.model.OrderGoods;
import com.istock.state.demo.model.OrderGoodsExample;

@Repository("orderGoodsService")
public class OrderGoodsService {

	@Autowired
	private OrderGoodsMapper mapper;
	
	public List<OrderGoods> findExpireOrderGoods(){
		OrderGoodsExample example = new OrderGoodsExample();
		OrderGoodsExample.Criteria criteria = example.createCriteria();
		
		criteria.andUpdateTimeBetween(DateUtils.addMinutes(new Date(), -30),DateUtils.addSeconds(new Date(), -1));
		criteria.andStatusIn(Arrays.asList(ChildOrderStatusEnum.WAIT.getValue() ,ChildOrderStatusEnum.PROCESSING.getValue()));
		//这边为了防止单次查询的数据量过多,可以增加orderBy和分页
		return mapper.selectByExample(example);
	}
	
	public OrderGoods findOrderGoodsById(Long id) {
		return mapper.selectByPrimaryKey(id);
	}
}
